<template>
  <section class="popup" v-show="isShow">
    <div class="toast-ordinary" v-if="type === 'ordinary'">
      <div class="dangerous">
        <div class="vertical"></div>
        <div class="spot"></div>
      </div>
      <div class="tip-text">{{ tipsText }}</div>
      <div class="confirm" @click="handlePopupConfirm">确认</div>
    </div>
    <div class="toast-sign-out" v-if="type === 'sign-out'">
      <div class="mask"></div>
      <div class="main">
        <div class="dangerous">
          <div class="vertical"></div>
          <div class="spot"></div>
        </div>
        <div class="tip-text">{{ tipsText }}</div>
        <div class="btn">
          <span class="wait" @click="handlePopupConfirm">再等等</span>
          <span class="quit" @click="handleSignOutLogin">退出登录</span>
        </div>
      </div>
    </div>
    <div class="toast-routine" v-if="type === 'routine'">
      {{ tipsText }}
    </div>
  </section>
</template>

<script>
export default {
  data() {
    return {
      isShow: false,
      tipsText: "请输入提示文字",
      type: "ordinary",
    };
  },
  methods: {
    handlePopupConfirm() {
      this.isShow = false;
      if (this.tipsText === "当前环境无法支付，请打开官方APP进行付款") {
        this.$bus.$emit("handlePopupConfirm");
      }
    },
    handleTipsText(value, type = "ordinary") {
      this.type = type;
      this.tipsText = value;
      this.isShow = true;
      if (type === "routine") {
        setTimeout(() => {
          this.type = "";
          this.isShow = false;
        }, 1000);
      }
    },
    handleSignOutLogin() {
      this.isShow = false;
      this.$bus.$emit("handleSignOutLogin");
    },
  },
};
</script>
<style lang="less" scoped>
.popup {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1;
  .dangerous {
    position: absolute;
    top: 30%;
    left: 50%;
    width: 75px;
    height: 75px;
    border: 3px solid #f8cb86;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    .vertical,
    .spot {
      position: absolute;
      left: 50%;
      transform: translateX(-50%);
      background-color: #f8cb86;
    }
    .vertical {
      top: 10px;
      width: 3px;
      height: 35px;
    }
    .spot {
      left: 50%;
      bottom: 16px;
      width: 4px;
      height: 4px;
    }
  }
  .toast-ordinary,
  .toast-sign-out .main {
    position: fixed;
    right: 0;
    left: 0;
    margin: 0 auto;
    border-radius: 5px;
    background-color: #ffffff;
    overflow: hidden;
    z-index: 1;
    animation: myDeformation 0.3s;
  }
  .tip-text {
    position: absolute;
    width: 100%;
    text-align: center;
    padding: 0 20px;
  }
  .toast-ordinary {
    top: 30%;
    width: 280px;
    height: 200px;
    .tip-text {
      bottom: 60px;
      font-weight: 700;
    }
    .confirm {
      position: absolute;
      bottom: 0;
      left: 50%;
      width: 100%;
      text-align: center;
      padding: 10px 0;
      background-color: #4cd964;
      font-weight: 700;
      font-size: 18px;
      color: #ffffff;
      transform: translateX(-50%);
    }
  }
  .toast-sign-out {
    .mask {
      position: fixed;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      background-color: #333333;
      opacity: 0.4;
    }
    .main {
      top: 15%;
      width: 94%;
      height: 300px;
      .dangerous {
        top: 25%;
        width: 90px;
        height: 90px;
        border: 4px solid #f8bb86;
        .vertical,
        .spot {
          background-color: #f8bb86;
        }
        .vertical {
          width: 5px;
          height: 45px;
        }
        .spot {
          width: 6px;
          height: 6px;
          border-radius: 50%;
        }
      }
      .tip-text {
        bottom: 120px;
        font-size: 30px;
      }
      .btn {
        display: flex;
        justify-content: space-evenly;
        position: absolute;
        bottom: 20px;
        width: 100%;
        padding: 0 50px;
        span {
          display: inline-block;
          padding: 10px 20px;
          border-radius: 5px;
          color: #ffffff;
        }
        .wait {
          background-color: #c1c1c1;
        }
        .quit {
          background-color: #dd6b55;
        }
      }
    }
  }
  @keyframes myDeformation {
    50% {
      transform: scale(0.7);
    }
    75% {
      transform: scale(1.1);
    }
  }
  .toast-routine {
    position: absolute;
    top: 50%;
    left: 50%;
    padding: 12px 30px;
    border-radius: 5px;
    background-color: #333333;
    font-size: 14px;
    color: #ffffff;
    transform: translate(-50%, -50%);
    white-space: nowrap;
  }
}
</style>